home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 25
/
Mac Magazin and MacEasy Magazine CD - Issue 25.iso
/
Grafik & Text
/
Alpha
/
Tcl
/
SystemCode
/
misc.tcl
< prev
next >
Wrap
Text File
|
1996-08-18
|
27KB
|
1,020 lines
#===========================================================================
# Information about a selection or window.
#===========================================================================
proc wordCount {} {
if {[set chars [expr {[selEnd] - [getPos]}]]} {
set lines [expr {[lindex [posToRowCol [selEnd]] 0] - [lindex [posToRowCol [getPos]] 0]}]
set text [getSelect]
} else {
set chars [maxPos]
set lines [lindex [posToRowCol $chars] 0]
set text [getText 0 [maxPos]]
}
if {[regsub -all {[!=;.,\(\#\=\):\{\"\}]} $text " " ret]} {
set words [llength $ret]
} else {
set words [llength $text]
}
alertnote [format "%d chars, %d words, %d lines" $chars $words $lines]
}
#=============================================================================
# Random functions.
#=============================================================================
#================================================================================
proc nextFunc {} {
searchFunc 1
}
proc prevFunc {} {
searchFunc 0
}
proc searchFunc {dir} {
global funcExpr
set pos [getPos]
select $pos
if ($dir==1) {
incr pos
} else {
set pos [expr $pos-1]
}
if {![catch {search -s -f $dir -i 1 -r 1 $funcExpr $pos} res]} {
eval select $res
}
}
#===========================================================================
# Comment routines.
#===========================================================================
proc commentPara {} {
}
#===========================================================================
# Sorting the selection.
# AUTHOR: David C. Black black@mpd.tandem.com
#===========================================================================
proc sortLines {} {
set ends [getEndpts]
set start [lindex $ends 0]
set end [lindex $ends 1]
if {$start == $end} {
alertnote "You must highlight the section you wish to sort."
return
}
if {[lookAt [expr $end-1]] != "\r"} {
alertnote "The selection must consist only of complete lines."
return
}
set text [getText $start [expr {$end-1}]]
set text [join [lsort [split $text "\r"]] "\r"]
replaceText $start [expr {$end-1}] $text
select $start $end
}
#===========================================================================
# Dump all current settings into a file.
#===========================================================================
proc insertGlobalSettings {} {
uplevel #0 {
foreach var [info globals] {
if {![catch {set $var}]} {
insertText "set " $var " \{" [set $var] "\}\r"
}
}
}
}
#================================================================================
# Substitute global variables in possibly nested list.
#================================================================================
proc subVars {words} {
global silly
global a
set silly $words
set out {}
foreach a $words {
if {[llength $a] == 1} {
lappend out [uplevel #0 {eval set x $a}]
} else {
lappend out [subVars $a]
}
}
return $out
}
#================================================================================
# Block shift left and right.
#================================================================================
proc shiftLeft {} {
global shiftChar
doShiftLeft "\t"
}
proc shiftLeftSpace {} {
global shiftChar
doShiftLeft " "
}
proc doShiftLeft {shiftChar} {
set start [lineStart [getPos]]
set end [nextLineStart [expr [selEnd] - 1]]
if {$start >= $end} {set end [nextLineStart $start]}
set text [split [getText $start [expr $end - 1]] "\r"]
set textout ""
foreach line $text {
if {[string index $line 0] == $shiftChar} {
lappend textout [string range $line 1 end]
} else {
lappend textout $line
}
}
set text [join $textout "\r"]
replaceText $start [expr $end - 1] $text
select $start [expr 1 + $start + [string length $text]]
}
proc shiftRight {} {
global shiftChar
doShiftRight "\t"
}
proc shiftRightSpace {} {
global shiftChar
doShiftRight " "
}
proc doShiftRight {shiftChar} {
set start [lineStart [getPos]]
set end [nextLineStart [expr [selEnd] - 1]]
if {$start >= $end} {set end [nextLineStart $start]}
set text [split [getText $start [expr $end - 1]] "\r"]
set textout ""
foreach line $text {
lappend textout $shiftChar$line
}
set text [join $textout "\r"]
replaceText $start [expr $end - 1] $text
select $start [expr 1 + $start + [string length $text]]
}
# rglobText [option list] dir pat
# 'dir' should be a properly formed directory, ending w/ a ':'. 'pat' should be
# a simple pattern w/ no directory specifications (i.e. "*.c").
proc rglobText {optlist dir pat} {
message "$dir"
set cmd [concat glob -t TEXT $optlist]
lappend cmd $dir$pat
if {[catch {eval $cmd} files]} {
set files ""
}
if {![catch {glob $dir*} all]} {
foreach f $all {
if {[file isdir $f]} {
set files [concat $files [rglobText $optlist $f: $pat]]
}
}
}
return $files
}
proc switchApp {} {
set procs ""
foreach p [processes] {
lappend procs [lindex $p 0]
}
set to [listpick -p "Switch to app:" [lsort $procs]]
if {[string length $to]} {
switchTo $to
}
}
proc selectAll {} {
select 0 [maxPos]
}
proc twiddle {} {
set pos [getPos]
if {!$pos || ($pos == [maxPos])} return;
if {[string length [set text [getSelect]]]} {
if {[string length $text] == 1} {
return
} else {
set sel [expr [selEnd] - 1]
set one [lookAt $sel]
set two [lookAt $pos]
replaceText $pos [expr $sel + 1] "$one[getText [expr $pos+1] $sel]$two"
select $pos [expr $sel+1]
return
}
}
set one [lookAt $pos]
set two [lookAt [expr $pos-1]]
replaceText [expr $pos-1] [expr $pos + 1] "$one$two"
select [expr $pos-1] [expr $pos + 1]
}
proc twiddleWords {} {
global wordBreakPreface wordBreak
if {[getPos] != [selEnd]} {
set start1 [getPos]; set end2 [selEnd]
select $start1
forwardWord; set end1 [getPos]
goto $end2
backwardWord; set start2 [getPos]
} else {
select [set pos [getPos]]
backwardWord; set start1 [getPos]
forwardWord; set end1 [getPos]
goto $pos
forwardWord; set end2 [getPos]
backwardWord; set start2 [getPos]
}
if {$start1 != $start2} {
set mid [getText $end1 $start2]
replaceText $start1 $end2 "[getText $start2 $end2]$mid[getText $start1 $end1]"
select $start1 $end2
}
}
#================================================================================
# Print a window using John Cho's Enscriptor (A text file printing app that
# works like Adobe Enscript.)
#
proc setupPrintMenu {} {
global pathComments defaultPrinter modifiedVars
if {![info exists defaultPrinter]} {
set defaultPrinter "Alpha"
lappend modifiedVars defaultPrinter
}
set m [list {/P<SPrint…} {/P<S<I<OPrint All…} {(-} Alpha Kodex Enscriptor {Drop•PS} PrettyC]
menu -m -n print -p printProc $m
foreach item $m {
if {$item == $defaultPrinter} {
markMenuItem -m print $item on
} else {
markMenuItem -m print $item off
}
}
}
proc printProc {menu item} {
global modifiedVars defaultPrinter pathComments
switch -glob $item {
"Print All" { if {$defaultPrinter == "Alpha"} {
printAll
} else {
foreach f [winNames -f] {
printFile $f
}
}
}
"Print" {printFile [car [winNames -f]]}
default {set defaultPrinter $item; lappend modifiedVars defaultPrinter; setupPrintMenu}
}
}
proc printFile {fname} {
global defaultPrinter
switch -glob $defaultPrinter {
"Alpha" {print}
"Kodex*" {openAndSendFile KoDX}
"Enscr*" {openAndSendFile Ens3}
"Drop*" {openAndSendFile {D•PS}}
"Pret*" {openAndSendFile niCe}
}
}
proc commentBox {} {
# Preliminaries
if [commentGetRegion Box] { return }
set commentList [commentCharacters Box]
if { [llength $commentList] == 0 } { return }
set begComment [lindex $commentList 0]
set begComLen [lindex $commentList 1]
set endComment [lindex $commentList 2]
set endComLen [lindex $commentList 3]
set fillChar [lindex $commentList 4]
set spaceOffset [lindex $commentList 5]
set aSpace " "
# First make sure we grab a full block of lines and adjust highlight
set start [getPos]
set start [lineStart $start]
set end [selEnd]
set end [nextLineStart [expr $end-1]]
select $start $end
# Now get rid of any tabs
if { $end < [maxPos] } then {
createTMark stopComment [expr $end+1]
tabsToSpaces
gotoTMark stopComment
set end [expr [getPos]-1]
removeTMark stopComment
} else {
tabsToSpaces
set end [maxPos]
}
select $start $end
set text [getText $start $end]
# Next turn it into a list of lines--possibly drop an empty 'last line'
# VMD May'95: changed this code segment because it
# previously had problems with empty lines in the
# middle of the text to be commented
set lineList [split $text "\r"]
set ll [llength $lineList]
if { [lindex $lineList [expr $ll -1] ] == {} } {
set lineList [lrange $lineList 0 [expr $ll -2] ]
}
set numLines [llength $lineList]
# end changes.
# Find the longest line length and determine the new line length
set maxLength 0
foreach thisLine $lineList {
set thisLength [string length $thisLine]
if { $thisLength > $maxLength } then {
set maxLength $thisLength
}
}
set newLength [expr {$maxLength + 2 + 2*$spaceOffset}]
# Now create the top & bottom bars and a blank line
set topBar $begComment
for { set i 0 } { $i < [expr {$newLength - $begComLen}] } { incr i } {
set topBar $topBar$fillChar
}
set botBar ""
for { set i 0 } { $i < [expr {$newLength - $endComLen}] } { incr i } {
set botBar $botBar$fillChar
}
set botBar $botBar$endComment
set blankLine $fillChar
for { set i 0 } { $i < [expr {$newLength - 2}] } { incr i } {
set blankLine $blankLine$aSpace
}
set blankLine $blankLine$fillChar
# For each line add stuff on left and spaces and stuff on right for box sides
# and concatenate everything into 'text'. Start with topBar; end with botBar
set text $topBar\r$blankLine\r
set frontStuff $fillChar
set backStuff $fillChar
for { set i 0 } { $i < $spaceOffset } { incr i } {
set frontStuff $frontStuff$aSpace
set backStuff $aSpace$backStuff
}
set backStuffLen [string length $backStuff]
for { set i 0 } { $i < $numLines } { incr i } {
set thisLine [lindex $lineList $i ]
set thisLine $frontStuff$thisLine
set thisLength [string length $thisLine]
set howMuchPad [expr {$newLength - $thisLength - $backStuffLen}]
for { set j 0 } { $j < $howMuchPad } { incr j } {
set thisLine $thisLine$aSpace
}
set thisLine $thisLine$backStuff
set text $text$thisLine\r
}
set text $text$blankLine\r$botBar\r
# Now replace the old stuff, turn spaces to tabs, and highlight
replaceText $start $end $text
set end [expr {$start+[string length $text]}]
cleverSpacesToTabs $start $end
}
proc uncommentBox {} {
# Preliminaries
if [commentGetRegion Box 1] { return }
set commentList [commentCharacters Box]
if { [llength $commentList] == 0 } { return }
set begComment [lindex $commentList 0]
set begComLen [lindex $commentList 1]
set endComment [lindex $commentList 2]
set endComLen [lindex $commentList 3]
set fillChar [lindex $commentList 4]
set spaceOffset [lindex $commentList 5]
set aSpace " "
set aTab \t
# First make sure we grab a full block of lines
set start [getPos]
set start [lineStart $start]
set end [selEnd]
set end [nextLineStart [expr $end-1]]
set text [getText $start $end]
# Make sure we're at the start and end of the box
set startOK [string first $begComment $text]
set endOK [string last $endComment $text]
set textLength [string length $text]
if { $startOK != 0 || ($endOK != [expr {$textLength-$endComLen-1}] || $endOK == -1) } then {
alertnote "You must highlight the entire comment box, including the borders."
return
}
# Now get rid of any tabs
if { $end < [maxPos] } then {
createTMark stopComment [expr $end+1]
tabsToSpaces
gotoTMark stopComment
set end [expr [getPos]-1]
removeTMark stopComment
} else {
tabsToSpaces
set end [maxPos]
}
select $start $end
set text [getText $start $end]
# Next turn it into a list of lines--possibly drop an empty 'last line'
# VMD May'95: changed this code segment because it
# previously had problems with empty lines in the
# middle of the text to be commented
set lineList [split $text "\r"]
set ll [llength $lineList]
if { [lindex $lineList [expr $ll -1] ] == {} } {
set lineList [lrange $lineList 0 [expr $ll -2] ]
}
set numLines [llength $lineList]
# end changes.
# Delete the first and last lines, recompute number of lines
set lineList [lreplace $lineList [expr $numLines-1] [expr $numLines-1] ]
set lineList [lreplace $lineList 0 0 ]
set numLines [llength $lineList]
# Eliminate 2nd and 2nd-to-last lines if they are empty
set eliminate $fillChar$aSpace$aTab
set thisLine [lindex $lineList [expr $numLines-1]]
set thisLine [string trim $thisLine $eliminate]
if { [string length $thisLine] == 0 } then {
set lineList [lreplace $lineList [expr $numLines-1] [expr $numLines-1] ]
}
set thisLine [lindex $lineList 0]
set thisLine [string trim $thisLine $eliminate]
if { [string length $thisLine] == 0 } then {
set lineList [lreplace $lineList 0 0 ]
}
set numLines [llength $lineList]
# For each line trim stuff on left and spaces and stuff on right and splice
set dropFromLeft [expr $spaceOffset+1]
set text ""
for { set i 0 } { $i < $numLines } { incr i } {
set thisLine [lindex $lineList $i]
set thisLine [string trimright $thisLine $eliminate]
set thisLine [string range $thisLine $dropFromLeft end]
set text $text$thisLine\r
}
# Now replace the old stuff, convert spaces back to tabs
replaceText $start $end $text
set end [expr {$start+[string length $text]}]
cleverSpacesToTabs $start $end
}
proc commentCharacters { purpose } {
global mode
switch $purpose {
"Paragraph" {
switch $mode {
"TeX" {return [list "%% " " %%" " % "] }
"Text" {return [list "!! " " !!" " ! "] }
"Fort" {return [list "CC " " CC" " C "] }
"Tcl" {return [list "## " " ##" " # "] }
"C" {return [list "/* " " */" " * "] }
"C++" {return [list "/* " " */" " * "] }
default {
alertnote "I don't know what comments should look like in this mode. Sorry."
return
}
}
}
"Box" {
switch $mode {
"TeX" {return [list "%" 1 "%" 1 "%" 3] }
"Text" {return [list "!" 1 "!" 1 "!" 3] }
"Fort" {return [list "C" 1 "C" 1 "C" 3] }
"Tcl" {return [list "#" 1 "#" 1 "#" 3] }
"C" {return [list "/*" 2 "*/" 2 "*" 3] }
"C++" {return [list "/*" 2 "*/" 2 "*" 3] }
default {
alertnote "I don't know what comments should look like in this mode. Sorry."
return
}
}
}
}
}
##
# Default is to look for a paragraph to comment out.
# If sent '1', then we look for a commented region to
# uncomment.
##
proc commentGetRegion { purpose {uncomment 0 } } {
if {[getPos] != [selEnd]} {
watchCursor
return 0
}
# there's no selection, so we try and generate one
set pos [getPos]
if $uncomment {
# uncommenting
set commentList [commentCharacters $purpose]
if { [llength $commentList] == 0 } { return 1}
switch $purpose {
"Box" {
set begComment [lindex $commentList 0]
set begComLen [lindex $commentList 1]
set endComment [lindex $commentList 2]
set endComLen [lindex $commentList 3]
set fillChar [lindex $commentList 4]
set spaceOffset [lindex $commentList 5]
# get length of current line
set line [getText [lineStart $pos] [nextLineStart $pos] ]
set c [string trimleft $line]
set slen [expr [string length $line] - [string length $c] ]
set start [string range $line 0 [expr $slen -1 ] ]
set pos [getPos]
if { $start == "" } {
set p $pos
while { [string first $fillChar $line] == 0 && \
[expr [string last $fillChar $line] + [string length $fillChar]] \
>= [string length [string trimright $line]] } {
set p [nextLineStart $p]
set line [getText [lineStart $p] [nextLineStart $p]]
}
set end [lineStart $p]
set p $pos
set line "${fillChar}"
while { [string first $fillChar $line] == 0 && \
[expr [string last $fillChar $line] + [string length $fillChar]] \
>= [string length [string trimright $line]] } {
set p [prevLineStart $p]
set line [getText [prevLineStart $p] [lineStart $p] ]
}
set begin [prevLineStart $p]
} else {
set line "$start"
set p $pos
while { [string range $line 0 [expr $slen -1] ] == "$start" } {
set p [nextLineStart $p]
set line [getText [lineStart $p] [nextLineStart $p]]
}
set end [prevLineStart $p]
set p $pos
set line "$start"
while { [string range $line 0 [expr $slen -1] ] == "$start" } {
set p [prevLineStart $p]
set line [getText [prevLineStart $p] [lineStart $p] ]
}
set begin [lineStart $p]
}
set beginline [getText $begin [nextLineStart $begin]]
if { [string first "$begComment" "$beginline" ] != $slen } {
message "First line failed"
return 1
}
set endline [getText $end [nextLineStart $end]]
set epos [string last "$endComment" "$endline"]
incr epos [string length $endComment]
set s [string range $endline $epos end ]
set s [string trimright $s]
if { $s != "" } {
message "Last line failed"
return 1
}
set end [nextLineStart $end]
select $begin $end
#alertnote "Sorry auto-box selection not yet implemented"
}
"Paragraph" {
set begComment [lindex $commentList 0]
set endComment [lindex $commentList 1]
set fillChar [lindex $commentList 2]
##
# basic idea is search back and forwards for lines
# that don't begin the same way and then see if they
# match the idea of the beginning and end of a block
##
set line [getText [lineStart $pos] [nextLineStart $pos] ]
set chk [string range $line 0 [string first $fillChar $line]]
if { [string trimleft $chk] != "" } {
message "Not in a comment block"
return 1
}
regsub -all { } $line " " line
set p [string first "$fillChar" "$line"]
set start [string range "$line" 0 [expr $p + [string length $fillChar] -1 ]]
set ll [commentGetFillLines $start]
set begin [lindex $ll 0]
set end [lindex $ll 1]
set beginline [getText $begin [nextLineStart $begin]]
if { [string first "$begComment" "$beginline" ] != $p } {
message "First line failed"
return 1
}
set endline [getText $end [nextLineStart $end]]
set epos [string last "$endComment" "$endline"]
incr epos [string length $endComment]
set s [string range $endline $epos end ]
set s [string trimright $s]
if { $s != "" } {
message "Last line failed"
return 1
}
#goto $end
set end [nextLineStart $end]
select $begin $end
}
}
} else {
# commenting out
set searchString {^[ \t]*$}
set searchResult1 [search -s -f 0 -r 1 -n $searchString $pos]
set searchResult2 [search -s -f 1 -r 1 -n $searchString $pos]
if {[llength $searchResult1]} then {
set posStart [expr [lindex $searchResult1 1] +1]
} else {
set posStart 0
}
if {[llength $searchResult2]} then {
set posEnd [lindex $searchResult2 0]
} else {
set posEnd [expr [maxPos] +1]
goto [maxPos]
insertText "\n"
}
select $posStart $posEnd
}
set str "Do you wish to "
if $uncomment { append str "uncomment" } else { append str "comment out" }
append str " this region?"
if { [askyesno $str] == "yes" } {
return 0
} else {
return 1
}
}
proc prevLineStart { pos } {
return [lineStart [expr [lineStart $pos]-1]]
}
proc commentSameStart { line start } {
regsub -all { } "$line" " " line
if { [string first "$start" "$line"] == 0 } {
return 1
} else {
return 0
}
}
proc commentGetFillLines { start } {
set pos [getPos]
regsub -all {[\t]} $start " " start
set line "$start"
set p $pos
while { [commentSameStart "$line" "$start"] } {
set p [nextLineStart $p]
set line [getText [lineStart $p] [nextLineStart $p]]
}
set end [lineStart $p]
set p $pos
set line "$start"
while { [commentSameStart "$line" "$start"] } {
set p [prevLineStart $p]
set line [getText [prevLineStart $p] [lineStart $p] ]
}
set begin [prevLineStart $p]
return [list $begin $end]
}
##
# Author: Vince Darley <mailto:vince@das.harvard.edu>
##
proc commentParagraph {} {
# Preliminaries
if [commentGetRegion Paragraph] { return }
set commentList [commentCharacters Paragraph]
if { [llength $commentList] == 0 } { return }
set begComment [lindex $commentList 0]
set endComment [lindex $commentList 1]
set fillChar [lindex $commentList 2]
# First make sure we grab a full block of lines and adjust highlight
set start [getPos]
set start [lineStart $start]
set end [selEnd]
set end [nextLineStart [expr $end-1]]
select $start $end
# Now get rid of any tabs
if { $end < [maxPos] } then {
createTMark stopComment [expr $end+1]
tabsToSpaces
gotoTMark stopComment
set end [expr [getPos]-1]
removeTMark stopComment
} else {
tabsToSpaces
set end [maxPos]
}
select $start $end
set text [getText $start $end]
# Next turn it into a list of lines--possibly drop an empty 'last line'
set lineList [split $text "\r"]
set ll [llength $lineList]
if { [lindex $lineList [expr $ll -1] ] == {} } {
set lineList [lrange $lineList 0 [expr $ll -2] ]
}
set numLines [llength $lineList]
# Find left margin for these lines
set lmargin 100
for { set i 0 } { $i < $numLines } { incr i } {
set l [lindex $lineList $i]
set lm [expr [string length $l] - [string length [string trimleft $l]]]
if { $lm < $lmargin } { set lmargin $lm }
}
set ltext ""
for { set i 0 } { $i < $lmargin } { incr i } {
append ltext " "
}
# For each line add stuff on left and concatenate everything into 'text'.
set text ${ltext}${begComment}\r
for { set i 0 } { $i < $numLines } { incr i } {
append text ${ltext}${fillChar}[string range [lindex $lineList $i ] $lmargin end]\r
}
append text ${ltext}${endComment}\r
# Now replace the old stuff, turn spaces to tabs, and highlight
replaceText $start $end $text
set end [expr {$start+[string length $text]}]
cleverSpacesToTabs $start $end
}
##
# Author: Vince Darley <mailto:vince@das.harvard.edu>
##
proc uncommentParagraph {} {
# Preliminaries
if [commentGetRegion Paragraph 1] { return }
set commentList [commentCharacters Paragraph]
if { [llength $commentList] == 0 } { return }
set begComment [lindex $commentList 0]
set endComment [lindex $commentList 1]
set fillChar [lindex $commentList 2]
set aSpace " "
set aTab \t
# First make sure we grab a full block of lines and adjust highlight
set start [getPos]
set start [lineStart $start]
set end [selEnd]
set end [nextLineStart [expr $end-1]]
select $start $end
set text [getText $start $end]
# Find left margin for these lines
set l [string range $text 0 [string first "\r" $text] ]
set lmargin [expr [string length $l] - [string length [string trimleft $l]]]
# Make sure we're at the start and end of the paragraph
set startOK [string first $begComment $text]
set endOK [string last $endComment $text]
set textLength [string length $text]
if { $startOK != $lmargin || ($endOK != [expr {$textLength-[string length $endComment]-1}] || $endOK == -1) } then {
alertnote "You must highlight the entire comment paragraph, including the tail ends."
return
}
# Now get rid of any tabs
if { $end < [maxPos] } then {
createTMark stopComment [expr $end+1]
tabsToSpaces
gotoTMark stopComment
set end [expr [getPos]-1]
removeTMark stopComment
} else {
tabsToSpaces
set end [maxPos]
}
select $start $end
set text [getText $start $end]
# Next turn it into a list of lines--possibly drop an empty 'last line'
set lineList [split $text "\r"]
set ll [llength $lineList]
if { [lindex $lineList [expr $ll -1] ] == {} } {
set lineList [lrange $lineList 0 [expr $ll -2] ]
}
set numLines [llength $lineList]
# Delete the first and last lines, recompute number of lines
set lineList [lreplace $lineList [expr $numLines-1] [expr $numLines-1] ]
set lineList [lreplace $lineList 0 0 ]
set numLines [llength $lineList]
# get the left margin
set lmargin [string first $fillChar [lindex $lineList 0]]
set ltext ""
for { set i 0 } { $i < $lmargin } { incr i } {
append ltext " "
}
# For each line trim stuff on left and spaces and stuff on right and splice
set eliminate $fillChar$aSpace$aTab
set dropFromLeft [expr [string length $fillChar] + $lmargin]
set text ""
for { set i 0 } { $i < $numLines } { incr i } {
set thisLine [lindex $lineList $i]
set thisLine [string trimright $thisLine $eliminate]
set thisLine ${ltext}[string range $thisLine $dropFromLeft end]
set text $text$thisLine\r
}
# Now replace the old stuff, turn spaces to tabs, and highlight
replaceText $start $end $text
set end [expr {$start+[string length $text]}]
cleverSpacesToTabs $start $end
}
proc cleverTabsToSpaces { start end } {
cleverSpacesTabs tabsToSpaces $start $end
}
proc cleverSpacesToTabs { start end } {
cleverSpacesTabs spacesToTabs $start $end
}
proc cleverSpacesTabs { fn start end } {
set e [expr $end+1]
if { $e > [maxPos] } {
goto $end
openLine
}
createTMark stopComment $e
select $start $end
$fn
gotoTMark stopComment
set end [expr [getPos]-1]
removeTMark stopComment
return [list $start $end]
}
#===============================================================================
proc stripNameCount str {
regsub { <\d+>} $str {} str
return $str
}
#===============================================================================
# Used to create a popup of all funcs in window. Routine
# should return list containing, consecutively, proc name and
# start of definition.
proc parseFuncsAlpha {} {
global mode sortFuncsMenu
if {[info procs "parseFuncs$mode"] != ""} {
return [parseFuncs$mode]
} else {
global funcExpr parseExpr
set pos 0
if $sortFuncsMenu {
while {[set res [search -s -f 1 -r 1 -i 0 -n $funcExpr $pos]] != ""} {
if {[regexp $parseExpr [getText [car $res] [cadr $res]] dummy word]} {
lappend m [list $word [car $res]]
}
set pos [cadr $res]
}
regsub -all "\[\{\}\]" [lsort -ignore $m] "" m
} else {
while {[set res [search -s -f 1 -r 1 -i 0 -n $funcExpr $pos]] != ""} {
if {[regexp $parseExpr [getText [car $res] [cadr $res]] dummy word]} {
lappend m $word [car $res]
}
set pos [cadr $res]
}
}
return $m
}
}